package test

import org.apache.spark.{SparkConf, SparkContext}

object test2 {
  def main(args: Array[String]): Unit = {
    val conf = new SparkConf().setAppName("RDDwork").setMaster("local")
    val sc = new SparkContext(conf)
    val rdd0 = sc.textFile("data/input/stu") //读取文件
    val rdd1 = rdd0.map(line => {
      val fileds = line.split(",") //按“,”分割
      (fileds(0), fileds(1).toInt)  // 将学生名字和分数放到一个元组中
    }).mapValues(score => if(score >= 60) "及格" else "不及格") //判断学生是否及格
    rdd1.collect().foreach(println)  // 输出学生名字和成绩状态
  }
}
